package com.njtcedu.microblog.website.content.web;

import java.util.List;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.njtcedu.microblog.common.entity.Content;
import com.njtcedu.microblog.website.content.service.ContentService;
import com.njtcedu.microblog.website.content.web.response.ContentResponse;
import com.njtcedu.microblog.website.home.web.response.CurrentUser;

@Controller
public class ContentAjaxController {

	@Inject
	private ContentService contentService;
	
	@RequestMapping(value = "/content", method = RequestMethod.POST)
	@ResponseBody
	public ContentResponse sendMessage(HttpServletRequest request, @RequestParam(value="sendContent", required = false) String sendContent, @RequestParam(value="contentType", required = false) String contentType) {
		CurrentUser currentUser = (CurrentUser)request.getSession().getAttribute("currentUser"); 
		return contentService.sendMessage(currentUser, sendContent, contentType);
	}
	
	@RequestMapping(value = "/content", method = RequestMethod.GET)
	@ResponseBody
	public List<Content> getContents() {
		return contentService.getContents();
	}
	
	@RequestMapping(value = "/content/delete/{contentId}", method = RequestMethod.DELETE)
	@ResponseBody
	public boolean removeContent(@PathVariable("contentId") Integer contentId) {
		return contentService.removeContent(contentId);
	}
}
